function rendToolBar() {
    var imgSrc = "../images/common/logo.png"
    var toolBarHtml = "<img class='logo' src ='"+ imgSrc +"' />\
                    <span class='item' id='file'>文件(F)</span>\
                    <span class='item' id='tool'>工具(D)</span>\
                    <span class='item' id='help'>帮助(H)</span>"


    $(".tool-bar").append(toolBarHtml)
}
rendToolBar()


var form = layui.form;
form.on('submit(solution_submit)', function(data){
    const solutionData = data.field
    sessionStorage.setItem('solutionInfo', JSON.stringify(solutionData))
    layer.msg('创建成功', { icon: 1, time: 1000});
    layer.closeAll()
});
form.on('submit(module_submit)', function(data){
    const moduleData = data.field
    sessionStorage.setItem('moduleInfo', JSON.stringify(moduleData))
    layer.msg('创建成功', { icon: 1, time: 1000});
    layer.closeAll()
});
form.on('submit(model_submit)', function(data){
    const modelData = data.field
    sessionStorage.setItem('modelInfo', JSON.stringify(modelData))
    layer.msg('创建成功', { icon: 1, time: 1000});
    layer.closeAll()
});

// 生成下拉菜单
var dropdown = layui.dropdown
dropdown.render({
    elem: "#file", // id
    data: [
        {
            title: "新建方案",
            id: "1",
            templet: '<img src="../images/tool/icon_ui_model.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "新建模块",
            id: "2",
            templet: '<img src="../images/tool/icon_ui_model.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "新建模型",
            id: "3",
            templet: '<img src="../images/tool/icon_ui_model.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "新建UIForm",
            id: "4",
            templet: '<img src="../images/tool/icon_ui_form.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "新建数据字典",
            id: "5",
            templet: '<img src="../images/tool/icon_data_dict.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "新建参照",
            id: "6",
            templet: '<img src="../images/tool/icon_refer.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "打开方案",
            id: "7",
            templet: '<img src="../images/tool/icon_open.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "打开模块",
            id: "8",
            templet: '<img src="../images/tool/icon_open_project.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "保存",
            id: "9",
            templet: '<img src="../images/tool/icon_save.png" style="width:20px; height:20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "保存所有",
            id: "10",
            templet: '<img src="../images/tool/icon_save_all.png" style="width:20px; height:20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "另存为",
            id: "11",
            templet: '<img src="../images/tool/icon_save_as.png" style="width:20px; height:20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "退出",
            id: "12",
            templet: '<img src="../images/tool/icon_exit.png" style="width:20px; height:20px;"/>&nbsp;{{d.title}}'
        }
    ],
    click: fileMenuCallBack
})
dropdown.render({
    elem: "#tool", // id
    data: [
        {
            title: "上传地址",
            id: "",
            templet: '<img src="../images/tool/icon_upload_address.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "数据源",
            id: "",
            templet: '<img src="../images/tool/icon_data_source.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "上传文件",
            id: "",
            templet: '<img src="../images/tool/upload_file.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "上传全部",
            id: "",
            templet: '<img src="../images/tool/icon_upload_all.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "发布文件",
            id: "",
            templet: '<img src="../images/tool/icon_publish_file.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "发布全部",
            id: "",
            templet: '<img src="../images/tool/icon_publish_all.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "生成代码",
            id: "",
            templet: '<img src="../images/tool/icon_create_code.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "生成全部",
            id: "",
            templet: '<img src="../images/tool/icon_create_all.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        }
    ],
    click: function(obj) {
        console.log(obj)
    }
})
dropdown.render({
    elem: "#help", // id
    data: [
        {
            title: "设计指南",
            id: "",
            templet: '<img src="../images/tool/icon_upload_address.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "个性化",
            id: "",
            templet: '<img src="../images/tool/icon_upload_address.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        },
        {
            title: "关于XRD",
            id: "",
            templet: '<img src="../images/tool/icon_upload_address.png" style="width: 20px; height: 20px;"/>&nbsp;{{d.title}}'
        }
    ],
    click: function(obj) {
        console.log(obj)
    }
})

// 点击【文件】菜单的回调
function fileMenuCallBack(obj) {
    console.log('callback-=====', obj)
    if(obj.title === '新建方案') {
        layer.open({
            type: 1,//类型
            area: ['400px','auto'],//定义宽和高
            title: '新建方案',//题目
            shadeClose: false,//点击遮罩层关闭
            content: $('#createSolution'), //打开的内容
            end: function () {
                $('#createSolution').hide()
            }
        });
    } else if (obj.title === '新建模块') {
        layer.open({
            type: 1,//类型
            area: ['400px','auto'],//定义宽和高
            title: '新建模块',//题目
            shadeClose: false,//点击遮罩层关闭
            content: $('#createModule'), //打开的内容
            end: function () {
                $('#createModule').hide()
            }
        });
    } else if (obj.title === '新建模型') {
        layer.open({
            type: 1,//类型
            area: ['400px','auto'],//定义宽和高
            title: '新建模型',//题目
            shadeClose: false,//点击遮罩层关闭
            content: $('#createModel'), //打开的内容
            end: function () {
                $('#createModel').hide()
            }
        });
    } else if (obj.title === '打开文件') {
        layer.open({
            type: 1,//类型
            area: ['400px','auto'],//定义宽和高
            title: '新建模型',//题目
            shadeClose: false,//点击遮罩层关闭
            content: $('#createModel'), //打开的内容
            end: function () {
                $('#createModel').hide()
            }
        });
    }
}

